import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import {ElMessage} from 'element-plus'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/home',
      name: 'home',
      component: HomeView,
      children:[
        {
          path: '/shouye',
          name: 'shouye',
          component: () => import('../views/shouye.vue'),
          children:[
            {
              path: '/',
              name: 'quanbu',
              component: () => import('../views/quanbu.vue')
            },{
              path: '/shipin',
              name: 'shipin',
              component: () => import('../views/shipin.vue')
            },{
              path: '/meishi',
              name: 'meishi',
              component: () => import('../views/meishi.vue')
            },{
              path: '/jiazhuang',
              name: 'jiazhuang',
              component: () => import('../views/jiazhuang.vue')
            },{
              path: '/meishi',
              name: 'meishi',
              component: () => import('../views/meishi.vue')
            },{
              path: '/yinshi',
              name: 'yinshi',
              component: () => import('../views/yinshi.vue')
            },{
              path: '/kexuekepu',
              name: 'kexuekepu',
              component: () => import('../views/kexuekepu.vue')
            },{
              path: '/car',
              name: 'car',
              component: () => import('../views/car.vue')
            },{
              path: '/shougong',
              name: 'shougong',
              component: () => import('../views/shougong.vue')
            },{
              path: '/sousuoTiaozhuan',
              name: 'sousuoTiaozhuan',
              component: () => import('../views/sousuoTiaozhuan.vue')
            }
          ]
        },{
          path: '/fabuzuoping',
          name: 'fabuzuoping',
          component: () => import('../views/fabuzuoping.vue')
        },{
          path: '/wodeJiemian',
          name: 'wodeJiemian',
          component: () => import('../views/wodeJiemian.vue')
        }

      ]
    },
    {
      path: '/about',
      name: 'about',
      component: () => import('../views/AboutView.vue')
    },{
      path: '/neirong',
      name: 'neirong',
      component: () => import('../views/neirong.vue')
    },{
      path: '/shipingNeirong',
      name: 'shipingNeirong',
      component: () => import('../views/shipingNeirong.vue')
    },{
      path: '/meishiNeirong',
      name: 'meishiNeirong',
      component: () => import('../views/meishiNeirong.vue')
    },{
      path: '/jiazhuangNeirong',
      name: 'jiazhuangNeirong',
      component: () => import('../views/jiazhuangNeirong.vue')
    },
    {
      path: '/yinshiNeirong',
      name: 'yinshiNeirong',
      component: () => import('../views/yinshiNeirong.vue')
    }, {
      path: '/kexuekepuNeirong',
      name: 'kexuekepuNeirong',
      component: () => import('../views/kexuekepuNeirong.vue')
    },
    {
      path: '/carNeirong',
      name: 'carNeirong',
      component: () => import('../views/carNeirong.vue')
    },{
      path: '/shougongNeirong',
      name: 'shougongNeirong',
      component: () => import('../views/shougongNeirong.vue')
    },{
      path: '/fabuWenzhang',
      name: 'fabuWenzhang',
      component: () => import('../views/fabuWenzhang.vue')
    },{
      path: '/denglu',
      name: 'denglu',
      component: () => import('../views/denglu.vue')
    },
    {
      path: '/dengluChengg',
      name: 'dengluChengg',
      component: () => import('../views/dengluChengg.vue')
    },
    {
      path: '/bianji',
      name: 'bianji',
      component: () => import('../views/bianji.vue')
    },{
      path: '/shipinBianji',
      name: 'shipinBianji',
      component: () => import('../views/shipinBianji.vue')
    },{
      path: '/meishiBianji',
      name: 'meishiBianji',
      component: () => import('../views/meishiBianji.vue')
    },{
      path: '/jiazhuangBianji',
      name: 'jiazhuangBianji',
      component: () => import('../views/jiazhuangBianji.vue')
    },{
      path: '/yinshiBianji',
      name: 'yinshiBianji',
      component: () => import('../views/yinshiBianji.vue')
    },{
      path: '/kexuekepuBianji',
      name: 'kexuekepuBianji',
      component: () => import('../views/kexuekepuBianji.vue')
    },{
      path: '/carBianji',
      name: 'carBianji',
      component: () => import('../views/carBianji.vue')
    },{
      path: '/shougonBianji',
      name: 'shougonBianji',
      component: () => import('../views/shougonBianji.vue')
    },{
      path: '/dengluchengongNeirong',
      name: 'dengluchengongNeirong',
      component: () => import('../views/dengluchengongNeirong.vue')
    },{
      path: '/dengluchenggongBianji',
      name: 'dengluchenggongBianji',
      component: () => import('../views/dengluchenggongBianji.vue')
    }
  ]
})

/**
 * 路由守卫
 */
router.beforeEach((to, from,next)=>{
  //判断是否是登录
  if(to.path==="/denglu" || to.path==="/" || to.path==="/wodeJiemian" || to.path==="/shipin" || to.path==="/meishi" || to.path==="/jiazhuang" || to.path==="/yinshi" || to.path==="/kexuekepu" || to.path==="/car" || to.path==="/shougong"){
    next()
  }
  else{
    const tokenobject = localStorage.getItem("token")
    if(tokenobject){
      next()
    }else{
      ElMessage.error("亲，你还没有登录~")
      next("/denglu")
    }
  }
    
})
export default router
